package com.lovo.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lovo.config.ApplicationConfig;
import com.lovo.model.UserDO;
import com.lovo.service.IUserService;
import com.lovo.service.UserService;
import com.lovo.vo.ResultVO;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "LoginServlet",value = "/login")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
               String phone =request.getParameter("phone");
               String pwd =request.getParameter("pwd");
                IUserService userService;
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
        userService = context.getBean(UserService.class);
         UserDO userDO=userService.login(phone,pwd);
        ResultVO resultVO = new ResultVO();
        resultVO.setStatus(1);
        resultVO.setData(userDO);
        response.getWriter().print(new ObjectMapper().writeValueAsString(resultVO));


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
